from marshmallow import fields
from src.baseapp.requestVerify.BaseRequestVerify import HeadersSchema, BaseSchema


class CaseListBodySchema(BaseSchema):
    name = fields.Str(required=False)
    priority = fields.List(required=False, cls_or_instance=fields.Integer)
    is_delete = fields.Integer(required=False)
    version_id = fields.Integer(required=False)
    update_start_time = fields.DateTime(required=False)
    update_end_time = fields.DateTime(required=False)
    create_start_time = fields.DateTime(required=False)
    create_end_time = fields.DateTime(required=False)
    directory_id = fields.Integer(required=False)


class CaseInfoBodySchema(BaseSchema):
    testcase_id = fields.Integer(required=True)


class AddCaseInfoBodySchema(BaseSchema):
    directory_id = fields.Integer(required=True)
    name = fields.Str(required=True)
    priority = fields.Integer(required=True)
    version_id = fields.Integer(required=True)
    description = fields.Str(required=False)
    condition = fields.Str(required=False)
    steps = fields.Str(required=True)
    expected_result = fields.Str(required=True)


class AddCaseBodySchema(BaseSchema):
    # 校验cases_info中的每个元素是否符合CaseInfoBodySchema的校验规则
    cases_info = fields.Nested(AddCaseInfoBodySchema, required=True, many=True)


class UpdateCaseBodySchema(AddCaseBodySchema):
    case_ids = fields.List(required=True, cls_or_instance=fields.Integer)


class DeleteCaseBodySchema(BaseSchema):
    case_ids = fields.List(required=True, cls_or_instance=fields.Integer)


class ImportCaseBodySchema(BaseSchema):
    directory_id = fields.Integer(required=True)
    file = fields.Raw(required=True)


class ImportCaseHeadersSchema(HeadersSchema):
    content_type = fields.Str(required=True, default='application/octet-stream')


class DirectoryListBodySchema(BaseSchema):
    directory_id = fields.Integer(required=False)
    directory_name = fields.Str(required=False)


class CreateDirectoryBodySchema(BaseSchema):
    parent_id = fields.Integer(required=True)
    name = fields.Str(required=True)


class DeleteDirectoryBodySchema(BaseSchema):
    directory_id = fields.Integer(required=True)


class UpdateDirectoryBodySchema(BaseSchema):
    directory_id = fields.Integer(required=True)
    name = fields.Str(required=False)
    parent_id = fields.Integer(required=False)
